﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using MDP.WebOpenPortal.Controllers.SSO;

namespace MDP.WebOpenPortal.Controllers
{
    public class SSOSimulationHttpModule : IHttpModule, IRequiresSessionState
    {
        public void Init(HttpApplication context)
        {
            context.AuthorizeRequest += new EventHandler(OnAuthorizeRequest);
        }

        protected void OnAuthorizeRequest(object sender, EventArgs e)
        {
            string userID = "v_yangqingfei";
            // 检查 用户为空 或 非 IClaimsPrincipal 类型
            if (HttpContext.Current.User == null || typeof(IClaimsPrincipal).IsInstanceOfType(HttpContext.Current.User) == false)
            {
                
                ClaimsIdentity userIdentity = new ClaimsIdentity()
                {
                    UserName = userID
                };
                
                ClaimsPrincipal userPrincipal = new ClaimsPrincipal(userIdentity);
                HttpContext.Current.User = userPrincipal;
                System.Threading.Thread.CurrentPrincipal = userPrincipal;
            }
        }



        public void Dispose()
        {
        }
    }
}